﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.DataModel;
using QLBH.Model.Controller;
using QLBH.ModelInterface;

namespace QLBH.FeatureModel
{
    public class PhieuNhapKhoCTModel:PhieuNhapKhoModel,IPhieuNhapKhoCTModel
    {
        private List<INKMatHangModel> mathang;

        public List<INKMatHangModel> MatHang
        {
            get { return mathang; }
            set { mathang = value; }
        }
        public PhieuNhapKhoCTModel()
            :base()
        {
            mathang = new List<INKMatHangModel>();
        }
        public PHIEUNHAPKHO ToEntity()
        {
            PHIEUNHAPKHO entity = base.ToEntity();

            foreach (NKMatHangModel model in mathang)
            {
                PHIEUNHAPKHOCT mhEntity = model.ToEntity();
                entity.PHIEUNHAPKHOCTs.Add(mhEntity);
                mhEntity.PNKID = entity.PNKID;
            }                                 
            return entity;
        }
        public void InitFromEntity(PHIEUNHAPKHO entity)
        {
            base.InitFromEntity(entity);

            List<PHIEUNHAPKHOCT> nkcts = PhieuNhapKhoCTController.GetInstance().FindBy(pnk => 
                pnk.PNKID == entity.PNKID).ToList();

            foreach (PHIEUNHAPKHOCT pnk in nkcts)
            {
                NKMatHangModel model = new NKMatHangModel();
                model.InitFromEntity(pnk);
                mathang.Add(model);
            }
        }
    }
}
